import java.util.concurrent.locks.ReentrantLock;
public class App implements Runnable {
  public static void main(String[] args) throws InterruptedException {
   App app = new App();
   Thread t1 = new Thread(app, "t1");
  Thread t2 = new Thread(app, "t2");
  Thread.sleep(10);
  t1.start();
  t2.start();
 }

 private ReentrantLock reentrantLock = new ReentrantLock(true);
 @Override
 public void run() {
  String str = "ABCD";
  for (char item : str.toCharArray()) {
   reentrantLock.lock();
   try {
    System.out.print(item);
   } finally {
    reentrantLock.unlock();
   }
  }
 }
}